package com.cmall.common.foundation.util;

import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

//import javax.servlet.ServletInputStream;
//import javax.servlet.http.HttpServletRequest;


import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;


/**
 * 工具类 - 公用
*/

public class CommonUtil {
	
	public static final String WEB_APP_ROOT_KEY = "webAppRoot";// WebRoot路径KEY
	public static final String PATH_PREPARED_STATEMENT_UUID = "\\{uuid\\}";// UUID路径占位符
	public static final String PATH_PREPARED_STATEMENT_DATE = "\\{date(\\(\\w+\\))?\\}";// 日期路径占位符
	public static Map<String, String> branchs = new HashMap<String, String>();
	public static final String COMMON_DATE_FORMAT = DateUtil.YYYYMMDDHHMMSS;
	public static final String CR = "CR";//盘点录入前缀
	
	
	public static Integer str2Num(String str){
		if(isEmpty(str)){
			return null;
		}else {
			return new BigDecimal(str.trim()).intValue();
		}
	}
	
	public static BigDecimal str2BigDecimal(String str){
		if(isEmpty(str)){
			return BigDecimal.ZERO;
		}else{
			return new BigDecimal(str.trim());
		}
	}
	/**
	 * 获取WebRoot路径
	 * 
	 * @return WebRoot路径
	 */
	public static String getWebRootPath() {
		return System.getProperty(WEB_APP_ROOT_KEY);
	}

	/**
	 * 随机获取UUID字符串(无中划线)
	 * 
	 * @return UUID字符串
	 */
	public static String getUUID() {
		String uuid = UUID.randomUUID().toString();
		return uuid.substring(0, 8) + uuid.substring(9, 13) + uuid.substring(14, 18) + uuid.substring(19, 23) + uuid.substring(24);
	}
	
	/**
	 * 获取实际路径
	 * 
	 * @param path
	 *            路径
	 */
	public static String getPreparedStatementPath(String path) {
		if (StringUtils.isEmpty(path)) {
			return null;
		}
		StringBuffer uuidStringBuffer = new StringBuffer();
		Matcher uuidMatcher = Pattern.compile(PATH_PREPARED_STATEMENT_UUID).matcher(path);
		while(uuidMatcher.find()) {
			uuidMatcher.appendReplacement(uuidStringBuffer, CommonUtil.getUUID());
		}
		uuidMatcher.appendTail(uuidStringBuffer);
		
		StringBuffer dateStringBuffer = new StringBuffer();
		Matcher dateMatcher = Pattern.compile(PATH_PREPARED_STATEMENT_DATE).matcher(uuidStringBuffer.toString());
		while(dateMatcher.find()) {
			String dateFormate = "yyyyMM";
			Matcher dateFormatMatcher = Pattern.compile("\\(\\w+\\)").matcher(dateMatcher.group());
			if (dateFormatMatcher.find()) {
				String dateFormatMatcherGroup = dateFormatMatcher.group();
				dateFormate = dateFormatMatcherGroup.substring(1, dateFormatMatcherGroup.length() - 1);
			}
			dateMatcher.appendReplacement(dateStringBuffer, new SimpleDateFormat(dateFormate).format(new Date()));
		}
		dateMatcher.appendTail(dateStringBuffer);
		
		return dateStringBuffer.toString();
	}
	
	public static String getCurrentDateTime(){
		SimpleDateFormat format = new SimpleDateFormat(COMMON_DATE_FORMAT);
        return format.format(new Date(System.currentTimeMillis()));
    }
	
	public static String getCurrentDateTimeByFormat(String fmt){
		SimpleDateFormat format = new SimpleDateFormat(fmt);
        return format.format(new Date(System.currentTimeMillis()));
    }
	
	public static void Debug(String str){
		System.out.println(getCurrentDateTime()+" "+str);
	}
	
	@SuppressWarnings({"rawtypes" })
	public static boolean isNotEmpty(Object pObj) {
		if (pObj == null)
			return false;
		if (pObj instanceof String) {
			if (((String) pObj).trim().length() == 0) {
				return false;
			}
		} else if (pObj instanceof Collection) {
			if (((Collection) pObj).size() == 0) {
				return false;
			}
		} else if (pObj instanceof Map) {
			if (((Map) pObj).size() == 0) {
				return false;
			}
		}
		return true;
	}


	/**
	 * @description 判断不为空多参数
	 * 
	 * @date 2017-07-21
	 * @param
	 */
	@SuppressWarnings("rawtypes")
	public static boolean isNotEmpty(Object... ary) {
		if (ary == null){
			return false;
		}
		for (Object pObj : ary) {
			if (pObj == null)
				return false;
			if (pObj instanceof String) {
				if (((String) pObj).trim().length() == 0) {
					return false;
				}
			} else if (pObj instanceof Collection) {
				if (((Collection) pObj).size() == 0) {
					return false;
				}
			} else if (pObj instanceof Map) {
				if (((Map) pObj).size() == 0) {
					return false;
				}
			}
		}
		return true;
	}
	/**
	 * 判断对象是否Empty(null或元素为0)<br>
	 * 实用于对如下对象做判断:String Collection及其子类 Map及其子类
	 * 
	 * @param pObj
	 *            待检查对象
	 * @return boolean 返回的布尔值
	 */
	@SuppressWarnings({"rawtypes" })
	public static boolean isEmpty(Object pObj) {
		if (pObj == null)
			return true;
		if (pObj instanceof String) {
			if (((String) pObj).trim().length() == 0) {
				return true;
			}
		} else if (pObj instanceof Collection) {
			if (((Collection) pObj).size() == 0) {
				return true;
			}
		} else if (pObj instanceof Map) {
			if (((Map) pObj).size() == 0) {
				return true;
			}
		}else if (pObj instanceof JSONArray){
			if (((JSONArray) pObj).size() == 0) {
				return true;
			}
		}
		return false;
	}

	/**
	 * @description 多参数判断空
	 * 
	 * @date 2017-07-21
	 * @param
	 */
	@SuppressWarnings("rawtypes")
	public static boolean isEmpty(Object... ary) {
		if (ary == null){
			return true;
		}
		for (Object pObj : ary) {
			if (pObj == null)
				return true;
			if (pObj instanceof String) {
				if (((String) pObj).trim().length() == 0) {
					return true;
				}
			} else if (pObj instanceof Collection) {
				if (((Collection) pObj).size() == 0) {
					return true;
				}
			} else if (pObj instanceof Map) {
				if (((Map) pObj).size() == 0) {
					return true;
				}
			} else if (pObj instanceof JSONArray){
				if (((JSONArray) pObj).size() == 0) {
					return true;
				}
			}
		}
		return false;
	}
	/**
	 * 对文件流输出下载的中文文件名进行编码 屏蔽各种浏览器版本的差异性
	 */
	/*public static String encodeChineseDownloadFileName(HttpServletRequest request, String pFileName) {
		String agent = request.getHeader("USER-AGENT");
		try {
			if (null != agent && -1 != agent.indexOf("MSIE")) {
				pFileName = URLEncoder.encode(pFileName, "utf-8");
			} else {
				pFileName = new String(pFileName.getBytes("utf-8"), "iso8859-1");
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return pFileName;
	}*/

	/**
	 * 根据日期获取星期
	 * 
	 * @param strdate
	 * @return
	 */
	public static String getWeekDayByDate(String strdate) {
		final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		SimpleDateFormat sdfInput = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		Date date = new Date();
		try {
			date = sdfInput.parse(strdate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.setTime(date);
		int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
		if (dayOfWeek < 0)
			dayOfWeek = 0;
		return dayNames[dayOfWeek];
	}
	
	 /** 
	    * 获得今天周几
		*
	    * @return int   Calender.MONDAY 星期一  Calender.THURSDAY 星期二  ...
		*
	    */  
	public static int getDayOfWeek(){
		return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
	}
	
	/**
	 * 获得指定时间是周几
	 *
     * @return int   Calender.MONDAY 星期一  Calender.THURSDAY 星期二  ...
	 */
	public static int getDayOfWeek(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal.get(Calendar.DAY_OF_WEEK);
	}
	
	    /** 
	    * 获得随即颜色
		* @return
	    * @return String  
		*
	    */  
	public static String getRandom(int count){
		String S = "0123456789ABCDEF";
		Random r = new Random();
		String tmp ="";
		for (int i=0;i<count;i++){
			int index = r.nextInt(S.length());
			tmp += S.charAt(index);
		}
		return tmp;
	}
	
	/**
	 * 获得随机数字
	 * @param count  字符长度
	 * @return
	 */
	public static String getRandomNumber(int count) {
		String S = "0123456789";
		Random r = new Random();
		String tmp ="";
		for (int i=0;i<count;i++){
			int index = r.nextInt(S.length());
			tmp += S.charAt(index);
		}
		return tmp;
	}
	
	public static String fixStringLen(String str,int len,String fixStr){
		if (isEmpty(str) || str.length()>len){
			return str;
		}
		int qty = len - str.length(); //缺少多少位
		String rtn = "";
		for (int i=0;i<qty;i++){
			rtn +=fixStr;
		}
		return rtn+str;
	}
	
	
	  /** 
	    * 把传入的字符串 转化成where xxx in (xxx) 的形式，
		* @param str  1,2,3,4
		* @return	('1','2','3','4')
	    * @return String  
		*
	    */  
	public static String getSqlWhereIn(String str){
		if (str == null || "".equals(str)) return "('')";
		
		if (str.indexOf(",") > 0){
			String[] list= str.split(",");
			StringBuffer sb = new StringBuffer("(");
			for (int i=0;i<list.length;i++){
				sb.append("'"+list[i]+"'");
				if (i != list.length - 1){
					sb.append(",");
				}
			}
			sb.append(")");
			return sb.toString();
		}else{
			return "('"+str+"')";
		}
	}
	
	/**
	 * 
	* @Title: generateDocumentNum 
	* @Description: 生成单据号
	* @param @param transNo 单据号类型  
	* @param @param branchNo  操作员的所属门店
	* @param @return    
	* @return String    返回一个随机生成的单据号
	* @throws
	 */
	public static String getSheetNo(String transNo,String branchNo){
		String documentId = transNo+getCurrentDateTimeByFormat("yyMMddHHmm")+getRandom(6);
		return documentId;
	}
	
	public static Date convertStrToDate(String str) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strDate = str;
		return sdf.parse(strDate);
	}
	public static Date convertStrToOnlyDate(String str) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String strDate = str;
		return sdf.parse(strDate);
	}
	public static Date convertStrToDate(String str,String format) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		String strDate = str;
		return sdf.parse(strDate);
	}
	
	public static String convertDateToStr(Date date,String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}
	
	 /** 
	    * 清空STRINGBUFFER
		* @param  sb
		*
	    * @return void  
		*
	    */  
	public static void clearStringBuffer(StringBuffer sb){
		sb.delete(0, sb.length());
	}
	
	public static String getOSName(){
		return System.getProperties().getProperty("os.name");
	}
	
	public static Boolean isWindows(){
		if (getOSName().toLowerCase().indexOf("window")>-1){
			return true;
		}else{
			return false;
		}
	}
	public static Boolean isLinux(){
		if (getOSName().toLowerCase().indexOf("linux")>-1){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 描述
	 * @param date1  开始时间
	 * @param date2 结束时间
	 * @return  返回集合
	 */
	@SuppressWarnings("static-access")
	public static List<String> getEndDate(Date date1,Date date2){
			List<String> list=new ArrayList<String>();
			Calendar cal1 = Calendar.getInstance();      
			cal1.setTime(date1);      
			Calendar cal2 = Calendar.getInstance();      
	        cal2.setTime(date2);      
	        long time1 = cal1.getTimeInMillis();                   	          
	        long time2 = cal2.getTimeInMillis();           
	        int  betweendays=(int) ((time2-time1)/(1000*3600*24));  
	        cal1.add(cal1.DATE,1);	       	        
	        SimpleDateFormat date=new SimpleDateFormat("yyyy-MM-dd");
	      //  System.out.println("获取cal1:"+date.format(cal2.getTime()));	      
	        for(int i=0;i<=betweendays;i++){
	        	Calendar caA = Calendar.getInstance();
	        	caA.setTime(date1);
	        	//System.out.println("i:"+i);
	        	//添加日期
	        	caA.add(cal2.DATE,i);
	        	Calendar cab = Calendar.getInstance();
	        	cab.setTime(caA.getTime());
	        	String week="";
				int weekDay=cab.get(cab.DAY_OF_WEEK)-1;
				switch (weekDay) {
				case 0:
					week="周日";
					break;
				case 1:
					week="周一";
					break;
				case 2:
					week="周二";
					break;
				case 3:
					week="周三";
					break;
				case 4:
					week="周四";
					break;
				case 5:
					week="周五";
					break;
				default:
					week="周六";
					break;
				}
				StringBuffer dates=new StringBuffer();
				dates.append(date.format(caA.getTime()));
				dates.append(" ");
				dates.append(week);
				list.add(dates.toString());
	        //	System.out.println("获取天数"+date.format(caA.getTime()));
	        }
	        return list;
	}
	/**
	 * 描述
	 * @param date1  开始时间
	 * @param date2 结束时间
	 * @return  返回时间差
	 */
	public static int daysAfter(Date date1,Date date2){
		Calendar cal1 = Calendar.getInstance();      
		cal1.setTime(date1);      
		Calendar cal2 = Calendar.getInstance();      
        cal2.setTime(date2);      
        long time1 = cal1.getTimeInMillis();                   	          
        long time2 = cal2.getTimeInMillis(); 
        //获取排班天数
      return (int) ((time2-time1)/(1000*3600*24))+1;  
	}
	
	/**
	 * 根据正则表达式查找符合规则的子串
	 * @param _regexp 正则表达式
	 * @param content 源字符串
	 * @return 返回子串
	 * @return List<String>  
	 */
	public static List<String> findString(String _regexp,String content){
		Pattern pattern = Pattern.compile(_regexp);  
	    Matcher match = pattern.matcher(content); 
	    List<String> list = new ArrayList<String>();
	    while(match.find()){
	    	list.add(match.group());
	    }
		return list;
	}
	
	
	/**
	 * 字符串解密
	 * @param s
	 * @return
	 * @return String
	 */
	public static String decrypt(String s){
        int iLen = 0;
        String sText =s;
        String sResult ="";
        //String sRtn = "";
        iLen = sText.length();
        for (int i =1;i <= iLen;i++){
            sResult =  (char)(sText.substring(i - 1, i ).codePointAt(0) - (2 * (iLen - i -2))) +sResult ;
        }
        return sResult;
    }

	/**
	 * 字符串加密
	 * @param str
	 * @return
	 * @return String
	 */
	public static String encrypt(String str){
		StringBuffer resStr = new StringBuffer();
		StringBuffer buf = new StringBuffer(str.trim());
		buf = buf.reverse();//字符串翻转
		for (int i = 1; i <= buf.length(); i++) {
			char c = (char)(((buf.substring(i-1, i)).codePointAt(0))+((buf.length() - i - 2) * 2));
			resStr.append(c);
		}
		return resStr.toString();
	}
	
	/**JAVA 加密
	 * @param strSrc 需要加密人字符串，支持中文
	 * @param encName  空位MD5，支持MD5 ,SHA-1 SHA-256
	 * @return String
	 */
	public static String encrypt(String strSrc, String encName) {
		MessageDigest md = null;
		String strDes = null;

		byte[] bt = strSrc.getBytes();
		try {
			if (encName == null || encName.equals("")) {
				encName = "MD5";
			}
			md = MessageDigest.getInstance(encName);
			md.update(bt);
			strDes = bytes2Hex(md.digest()); // to HexString
		} catch (NoSuchAlgorithmException e) {
			System.out.println("Invalid algorithm.");
			return null;
		}
		return strDes;
	}

	public static String bytes2Hex(byte[] bts) {
		String des = "";
		String tmp = null;
		for (int i = 0; i < bts.length; i++) {
			tmp = (Integer.toHexString(bts[i] & 0xFF));
			if (tmp.length() == 1) {
				des += "0";
			}
			des += tmp;
		}
		return des;
	}
	/**
	 * 日期加天数
	 * @param date 日期 格式yyyy-mm-dd HH:mm:ss
	 * @param days 天数
	 * @return
	 * @return String yyyy-mm-dd HH:mm:ss
	 */
	public static String dateAdd(String date,int days){
		  SimpleDateFormat format = new SimpleDateFormat(DateUtil.YYYYMMDDHHMMSS);  
		  try {
			Date da=format.parse(date);
			  Calendar ca = Calendar.getInstance();  
			  ca.setTime(da);   
			  ca.add(Calendar.DATE,days);// 为增加的天数
			  da = ca.getTime();  
			  String backTime = format.format(da);  
			 return backTime;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	//获取MAC地址的方法  
    private static String getMACAddress(InetAddress ia)throws Exception{  
        //获得网络接口对象（即网卡），并得到mac地址，mac地址存在于一个byte数组中。  
        byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();  
          
        //下面代码是把mac地址拼装成String  
        StringBuffer sb = new StringBuffer();  
          
        for(int i=0;i<mac.length;i++){  
            if(i!=0){  
                sb.append("-");  
            }  
            //mac[i] & 0xFF 是为了把byte转化为正整数  
            String s = Integer.toHexString(mac[i] & 0xFF);  
            sb.append(s.length()==1?0+s:s);  
        }  
          
        //把字符串所有小写字母改为大写成为正规的mac地址并返回  
        return sb.toString().toUpperCase();  
    }
    
	public static String getMAC(){
    	String macAddress = "";
    	try {
    		InetAddress ia = InetAddress.getLocalHost();//获取本地IP对象  
    		macAddress = getMACAddress(ia);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return macAddress;
    }
	
	/**
	 * 日期加天数
	 * @param date 日期 格式
	 * @param days 天数 ：加一天1；减5天 -5
	 * @return
	 * @return date
	 */
	public static Date dateAdd(Date date,int days){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, days);
		return calendar.getTime();
	}
	
	/**
	 * getIntervalDays
	 * 两个日期间隔的天数
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public static int getIntervalDays(Date startDate,Date endDate){
		int intervalDays = 0;
		Calendar calendarStartDate = Calendar.getInstance();
		Calendar calendarEndDate = Calendar.getInstance();
		calendarStartDate.setTime(startDate);
		calendarEndDate.setTime(endDate);
		//如果开始时间大于结束时间返回0
		if (calendarStartDate.after(calendarEndDate)) {
			return 0;
		}else {
			int intervalYears = calendarEndDate.get(Calendar.YEAR) - calendarStartDate.get(Calendar.YEAR);
			intervalDays = calendarEndDate.get(Calendar.DAY_OF_YEAR) - calendarStartDate.get(Calendar.DAY_OF_YEAR);
			for (int i = 0; i < intervalYears; i++) {
				calendarStartDate.set(Calendar.YEAR, (calendarStartDate.get(Calendar.YEAR) + 1));
				intervalDays += calendarStartDate.getMaximum(Calendar.DAY_OF_YEAR);
			}
			return intervalDays;
		}
	}
	/**
	 * 将驼峰法命名的字符串转换为数据库中的字段名
	 * @param s
	 * @return
	 */
	public static String toUnderlineName(String s) {
        if (s == null) {
            return null;
        }
 
        StringBuilder sb = new StringBuilder();
        boolean upperCase = false;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
 
            boolean nextUpperCase = true;
 
            if (i < (s.length() - 1)) {
                nextUpperCase = Character.isUpperCase(s.charAt(i + 1));
            }
 
            if ((i >= 0) && Character.isUpperCase(c)) {
                if (!upperCase || !nextUpperCase) {
                    if (i > 0) sb.append('_');
                }
                upperCase = true;
            } else {
                upperCase = false;
            }
 
            sb.append(Character.toLowerCase(c));
        }
 
        return sb.toString();
    }
	/**将数据库命名字段转换为驼峰法命名
	 * 
	 */
    public static String toCamelCase(String s) {
        if (s == null) {
            return null;
        }
 
        s = s.toLowerCase();
 
        StringBuilder sb = new StringBuilder(s.length());
        boolean upperCase = false;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
 
            if (c == '_') {
                upperCase = true;
            } else if (upperCase) {
                sb.append(Character.toUpperCase(c));
                upperCase = false;
            } else {
                sb.append(c);
            }
        }
 
        return sb.toString();
    }
 
    /**
	 * 获得今天是星期几
	 * @return
	 */
	public static int dayOfWeek(){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		int dofw = cal.get(Calendar.DAY_OF_WEEK);
		if(dofw==1){
			return 7;
		}else{
			return dofw-1;
		}
	}
	
	
	/**
	 * 生成单据号的方法
	 * @param sheetType 促销类型
	 * @return String 单据号
	 */
	public static String createSheetNo(String sheetType){
		String documentId = sheetType+CommonUtil.getCurrentDateTimeByFormat("yyMMddHHmm")+CommonUtil.getRandom(6);
		return documentId;
	}
	
	/**
	 * 生成规则号
	 * @param sheetType 促销类型
	 * @return String
	 */
	public  static String createRuleNo(String sheetType){
		String documentId = sheetType+CommonUtil.getCurrentDateTimeByFormat("yyMMddHHmm")+CommonUtil.getRandom(6);
		return documentId;
	}
	
	/**
	 * 生成补偿编码
	 * @param giveType 促销类型
	 * @return String
	 */
	public  static String createGiveNo(String giveType){
		String documentId = giveType+CommonUtil.getCurrentDateTimeByFormat("yyMMddHHmm")+CommonUtil.getRandom(6);
		return documentId;
	}

	/**
	 * @description id数组转字符串 e.g. 将 [1,2,3,4] 转为 1,2,3,4
	 * 
	 * @date 2017-06-08
	 * @param
	 */
	public static String convertLongAryToStr(Long[] ids){
		String str = "";
		for (Long id : ids) {
			str+=id+",";
		}
		if (str.endsWith(",")){
			str=str.substring(0,str.length()-1);
		}
		return str;
	}

	/**
	 * 校验特殊字符
	 * @param str
	 * @return
	 * @throws PatternSyntaxException
	 */
	public static boolean checkSpecialChar(String str) throws PatternSyntaxException {
		// 清除掉所有特殊字符
		String regEx =  ".*[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？\\\\]+.*";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.matches();
	}
	/**
	 * 检测是否有emoji字符
	 *
	 * @param source
	 * @return 一旦含有就抛出
	 */
	public  boolean containsEmoji(String source) {
		if (StringUtil.isEmpty(source)) {
			return false;
		}
		int len = source.length();
		for (int i = 0; i < len; i++) {
			char codePoint = source.charAt(i);
			if (!isNotEmojiCharacter(codePoint)) {
				//判断到了这里表明，确认有表情字符
				return true;
			}
		}
		return false;
	}

	/**
	 * 判断是否为非Emoji字符
	 *
	 * @param codePoint 比较的单个字符
	 * @return
	 */
	private boolean isNotEmojiCharacter(char codePoint) {
		return (codePoint == 0x0) ||
				(codePoint == 0x9) ||
				(codePoint == 0xA) ||
				(codePoint == 0xD) ||
				((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
				((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) ||
				((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));
	}

	/**
	 * 利用正则表达式判断字符串是否是数字
	 * @param str
	 * @return
	 */
	public static boolean isNumeric(String str){
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNum = pattern.matcher(str);
		if( !isNum.matches() ){
			return false;
		}
		return true;
	}
}